package com.ouc.openplatform.ktsy.task;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;   
 public class NJ_GetOrdersFromSqlServer {   
	//取order表用
    public static List<NJ_VIEW_ORDER>  nj_Getdata() {   
	String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动   
    String dbURL = "jdbc:sqlserver://10.136.124.1:1433; DatabaseName=iMES_HD"; //连接服务器和数据库test   
    String userName = "XG_User"; //默认用户名   
    String userPwd = "Haier,123"; //安装sql server 2005时的密码   
    Connection dbConn;   
    Statement stmt = null; 
    ResultSet rs = null; 
    List<NJ_VIEW_ORDER> orderList=new ArrayList<NJ_VIEW_ORDER>();
    	try {
			Class.forName(driverName);
			dbConn = DriverManager.getConnection(dbURL, userName, userPwd);   
	    	System.out.println("Connection Successful!\nUpdate order now------------\n"); //如果连接成功 控制台输出Connection Successful! 
	    	String SQL = "SELECT  * FROM View_Order"; 
	    	stmt = dbConn.createStatement(); 
	    	rs = stmt.executeQuery(SQL); 
	    	while (rs.next()) { 
	    		NJ_VIEW_ORDER order=new  NJ_VIEW_ORDER();
	    		//order.setId(id);
	    		order.setWorkOperationoutmainitemcode(rs.getString(1));
	    		order.setWorkOperationoutmainitemqty(rs.getInt(2));
	    		order.setWorkuserDay(rs.getString(3));
	    		order.setWorkuserBaoxiao(rs.getString(4));
	    		order.setWorkuserMordercode(rs.getString(5));
	    		order.setWorkuserLinename(rs.getString(6));
	    		order.setWorkuserLinecode(rs.getString(7));
	    		order.setProductdescription(rs.getString(8));
	    		orderList.add(order);
	        } 
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}   
    	 return orderList;
    }
    //取orderdetail表用
    public static List<NJ_VIEW_ORDERDETAIL>  nj_Getdatadetail() {   
    	String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载JDBC驱动   
        String dbURL = "jdbc:sqlserver://10.136.124.1:1433; DatabaseName=iMES_HD"; //连接服务器和数据库test   
        String userName = "XG_User"; //默认用户名   
        String userPwd = "Haier,123"; //安装sql server 2005时的密码   
        Connection dbConn;   
        Statement stmt = null; 
        ResultSet rs = null; 
        List<NJ_VIEW_ORDERDETAIL> orderList=new ArrayList<NJ_VIEW_ORDERDETAIL>();
        	try {
    			Class.forName(driverName);
    			dbConn = DriverManager.getConnection(dbURL, userName, userPwd);   
    	    	System.out.println("Update orderdetail now------------\n"); //如果连接成功 控制台输出Connection Successful! 
    	    	String SQL = "SELECT  * FROM View_OrderDetail"; 
    	    	stmt = dbConn.createStatement(); 
    	    	rs = stmt.executeQuery(SQL); 
    	    	while (rs.next()) { 
    	    		NJ_VIEW_ORDERDETAIL order=new  NJ_VIEW_ORDERDETAIL();
    	    		//order.setId(id);
    	    		order.setWorkuserBarcode(rs.getString(5));
    	    		order.setWorkOperationoutmainitemcode(rs.getString(1));
    	    		order.setWorkOperationoutmainitemqty(rs.getInt(2));
    	    		order.setWorkuserDay(rs.getString(3));
    	    		order.setWorkuserBaoxiao(rs.getString(4));
    	    		order.setWorkuserMordercode(rs.getString(6));
    	    		order.setWorkuserLinename(rs.getString(7));
    	    		order.setWorkuserLinecode(rs.getString(8));
    	    		order.setWorkuserRightmostitemname(rs.getString(9));
    	    		orderList.add(order);
    	        } 
    		} catch (ClassNotFoundException e) {
    			e.printStackTrace();
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}   
        	 return orderList;
        }
   }  
